package boot;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @program: springbootitem
 * @description: 接口返回值对象
 * @author: wdd
 * @create: 2019-08-16 17:01
 */
@ApiModel("接口返回值对象")
public class ResultModel<T> {

    @ApiModelProperty("状态码")
    private Long code;
    @ApiModelProperty("描述信息")
    private String message;
    @ApiModelProperty("业务数据")
    private T data;

    public ResultModel() {

    }

    public ResultModel(String message) {
        this.message = message;
    }

    public ResultModel(T data) {
        this.code = 10200L;
        this.message = "SUCCESS";
        this.data = data;
    }

    public ResultModel(String message, T data) {
        this.code = 10200L;
        this.message = message;
        this.data = data;
    }

    public static<T> ResultModel<T> success() {
        ResultModel resultModel = new ResultModel();
        resultModel.setCode((long) ResultCodeEnum.SUCCESS.code());
        resultModel.setMessage("SUCCESS");
        return resultModel;
    }

    public static<T> ResultModel<T> error(Integer code, String message) {
        ResultModel resultModel = new ResultModel();
        resultModel.setCode((long) code);
        resultModel.setMessage(message);
        return resultModel;
    }

    public static<T> ResultModel<T> error(String message) {
        ResultModel resultModel = new ResultModel();
        resultModel.setCode((long) 10400);
        resultModel.setMessage(message);
        return resultModel;
    }

    public static<T> ResultModel<T> success(T data) {
        return new ResultModel(data);
    }

    public static<T> ResultModel<T> success(String message, T data) {
        return new ResultModel(message, data);
    }

    public Long getCode() {
        return code;
    }

    public void setCode(Long code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}